﻿using System;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;

namespace zframe.loader
{
    public class AssetBundleLoader: BaseResLoader
    {
        public AssetBundle assetBundle {
            get { 
                return (AssetBundle)_asset;
            }
        }
        public AssetBundleLoader(string url, int priority=0) : base(url, priority)
        {

        }

        protected override void Init()
        {
            request = UnityWebRequestAssetBundle.GetAssetBundle(_url);
            base.Init();    
        }
        protected override void OnLoaded()
        {
            Debug.Log("OnLoaded now=" + DateTimeOffset.Now.ToUnixTimeMilliseconds() + ",fName=" + Path.GetFileName(_url));
            if (_status==LoaderStatus.Loaded)
            {
                var ab = DownloadHandlerAssetBundle.GetContent(request);
                _asset = ab;
            }
            base.OnLoaded();

        }
    }
}
